package cn.ym.system.controller;

import cn.ym.basic.exception.BusinessException;
import cn.ym.basic.utils.AjaxResult;
import cn.ym.basic.utils.PageList;
import cn.ym.system.domain.Systemdictionarydetail;
import cn.ym.system.query.SystemdictionarydetailQuery;
import cn.ym.system.service.SystemdictionarydetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接口类：数据字典明细
 */
@RestController
@RequestMapping("/systemdictionarydetail")
@Api(value = "数据字典明细接口" ,description = "处理数据字典明细的所有请求")
public class SystemdictionarydetailController {
    @Autowired
    private SystemdictionarydetailService systemdictionarydetailService;
    /**
     * 接口：添加或修改数据字典明细信息
     */
    @ApiOperation(value = "添加或修改数据字典明细信息")
    @PutMapping
    public AjaxResult save(@RequestBody Systemdictionarydetail systemdictionarydetail){

            if(systemdictionarydetail.getId()==null){
                systemdictionarydetailService.add(systemdictionarydetail);
            }else {
                systemdictionarydetailService.update(systemdictionarydetail);
            }
            return new AjaxResult();


    }

    /**
     *接口：删除单个数据字典明细信息
     */
    @ApiOperation(value = "删除单个数据字典明细信息")
    @DeleteMapping("/{id}")
    public AjaxResult del(@PathVariable("id") Long id){

            systemdictionarydetailService.delete(id);
            return new AjaxResult();

    }

    /**
     * 接口：查询所有数据字典明细信息
     */
    @ApiOperation(value = "查询所有数据字典明细信息")
    @GetMapping
    public List<Systemdictionarydetail> findAll(){
        return systemdictionarydetailService.findAll();
    }

    /**
     * 接口：查询单个数据字典明细信息
     */
    @ApiOperation(value = "查询单个数据字典明细信息")
    @GetMapping("/{id}")
    public Systemdictionarydetail findOne(@PathVariable("id") Long id){
        return systemdictionarydetailService.findOne(id);
    }


    /**
     * 接口：批量删除数据字典明细信息
     */
    @ApiOperation(value = "批量删除数据字典明细信息")
    @PatchMapping
    public AjaxResult patchDel(@RequestBody Long[]  ids){

            systemdictionarydetailService.patchDel(ids);
            return new AjaxResult();

    }

    /**
     * 接口：分页查询 + 高级查询
     */
    @ApiOperation(value = "分页查询或高级查询")
    @PostMapping
    public PageList<Systemdictionarydetail> queryPage(@RequestBody SystemdictionarydetailQuery systemdictionarydetailQuery){
        return systemdictionarydetailService.queryPage(systemdictionarydetailQuery);
   }


    /**
     * 接口：查询指定types_id数据字典明细信息
     */
    @ApiOperation(value = "查询指定id数据字典明细信息")
    @GetMapping("/loadquery/{id}")
    public List<Systemdictionarydetail> loadqueryByTypesId(@PathVariable("id") Long id){

        return systemdictionarydetailService.loadqueryByTypesId(id);
    }

}
